package presentacion.vista;

import presentacion.vista.*;
import presentacion.util.Ventana;
import java.util.List;
import accesoDatos.vo.Producto;
import accesoDatos.vo.Empleado;
import accesoDatos.vo.Pedido;
import accesoDatos.dao.DaoProducto;
import accesoDatos.dao.DaoEmpleado;
import accesoDatos.dao.DaoPedido;
import accesoDatos.util.Log;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import logicaNegocio.servicios.BuscarPorCampo;
import logicaNegocio.servicios.MenuDelDia;
import presentacion.vista.filechooser.MyFileChooser;
import java.awt.print.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 *
 * @author  Familia
 */
public class VistaAdministrador extends javax.swing.JFrame implements Printable {

    private JFrame parent = null;
    private Empleado empleado = null;
    private DialogoCambiarContraseña cambiarContraseña = null;
    private MyFileChooser fileChooser = null;
    private int idPedidoActual = 0;
    private List<JButton> botones = new ArrayList<JButton>();
    private List<Pedido> pedidos = new ArrayList<Pedido>();

    /** Creates new form VistaAdministrador */
    public VistaAdministrador(JFrame parent, Empleado empleado) {
        initComponents();
        this.parent = parent;
        this.empleado = empleado;
        generarMenuDelDia();
        campoNombre.setText(empleado.getNombre());
        campoCargo.setText(empleado.getCargo());
        pedidos = DaoPedido.readAll();
        cargarMesas(panelMesas);
        campoId.setText(empleado.getId().toString());
        Log.setEvento("Servidor", "INFO", "Se Ejecuta Interfaz de Administrador");
        Ventana.pantallaCompleta(this);
        botonModificar.setEnabled(false);
        botonEliminar.setEnabled(false);
        this.setVisible(true);
        parent.setVisible(false);
        comboBoxCampos.setEnabled(false);
        campoBuscar.setEnabled(false);
        botonCrear.setEnabled(false);


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void cargarMesas(JPanel panel) {
        pack();
        int anchoDelPadre = panel.getParent().getWidth();
        panel.setPreferredSize(new Dimension(anchoDelPadre, 1));
        botones.removeAll(botones);
        panel.removeAll();

        int espacioEntreBotones = 10;
        int filas = 0;


        for (int i = 0; i < pedidos.size(); i++) {
            if (pedidos.get(i).getEnCurso() == true) {
                JButton botonMesa = new JButton();
                // Propiedades del boton


                botonMesa.setSize(210, 80);
                botonMesa.setLocation(10, filas + espacioEntreBotones);
                botonMesa.setFont(new Font("Tahoma", 0, 18));
                botonMesa.setName(String.valueOf(pedidos.get(i).getMesa()));
                botonMesa.setText("Mesa " + String.valueOf(pedidos.get(i).getMesa()));
                botonMesa.setToolTipText("Mesa " + String.valueOf(pedidos.get(i).getMesa()));
                botonMesa.addActionListener(new java.awt.event.ActionListener() {

                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        obtenerPedidoMesa(evt);
                    }
                });


                // Ubicacion del proximo boton            
                filas += 90;

                // Adicion del boton
                botones.add(botonMesa);
                panel.add(botones.get(botones.size() - 1));

                //Ampliacion del panel contenedor
                pack();
                panel.setPreferredSize(new Dimension(anchoDelPadre, (int) (botonMesa.getLocation().getY() + 80 + espacioEntreBotones)));
                panel.updateUI();
            }

            // Refresco
            pack();
            panel.updateUI();
        }

    }

    private void obtenerPedidoMesa(java.awt.event.ActionEvent evt) {
        JButton boton = (JButton) evt.getSource();
        int numMesa = Integer.parseInt(boton.getName());
        double total = 0;
        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();
        modeloTabla.addColumn("Cantidad");
        modeloTabla.addColumn("Producto");
        modeloTabla.addColumn("Precio");

        for (int indexMesas = 0; indexMesas < pedidos.size(); indexMesas++) {
            if (pedidos.get(indexMesas).getMesa() == numMesa) {
                idPedidoActual = pedidos.get(indexMesas).getId();
                for (int i = 0; i < pedidos.get(indexMesas).getProductos().size(); i++) {
                    modeloTabla.addRow(new String[]{"1", pedidos.get(indexMesas).getProductos().get(i).getNombre(), String.valueOf(pedidos.get(indexMesas).getProductos().get(i).getPrecio())});
                    total += pedidos.get(indexMesas).getProductos().get(i).getPrecio();
                }
            }

        }
        tablaPedido.setModel(modeloTabla);
        campoTotal.setText(String.valueOf(total));
    }

    private javax.swing.table.DefaultTableModel generarCamposTabla() {
        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();

        if (radioProducto.isSelected()) {
            modeloTabla.addColumn("id");
            modeloTabla.addColumn("Nombre");
            modeloTabla.addColumn("Tipo");
            modeloTabla.addColumn("Precio");
            modeloTabla.addColumn("EstaEnMenu");
            modeloTabla.addColumn("Eliminado");
        }
        if (radioEmpleado.isSelected()) {
            modeloTabla.addColumn("id");
            modeloTabla.addColumn("Nombre");
            modeloTabla.addColumn("Cargo");
            modeloTabla.addColumn("Telefono");
            modeloTabla.addColumn("Celular");

        }
        if (radioVenta.isSelected()) {
            modeloTabla.addColumn("id");
            modeloTabla.addColumn("Mesa");
            modeloTabla.addColumn("EnCurso");
            modeloTabla.addColumn("Fecha");
            modeloTabla.addColumn("Empleado");
        }
        return modeloTabla;
    }

    private void generarMenuDelDia() {
        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();
        modeloTabla.addColumn("id");
        modeloTabla.addColumn("Nombre");
        modeloTabla.addColumn("Tipo");
        modeloTabla.addColumn("Precio");

        List<Producto> menu = MenuDelDia.getMenuDelDia();
        modeloTabla.setRowCount(menu.size());

        for (int fila = 0; fila < menu.size(); fila++) {
            modeloTabla.setValueAt(menu.get(fila).getId(), fila, 0);
            modeloTabla.setValueAt(menu.get(fila).getNombre(), fila, 1);
            modeloTabla.setValueAt(menu.get(fila).getTipo(), fila, 2);
            modeloTabla.setValueAt(menu.get(fila).getPrecio(), fila, 3);
        }
        tablaMenu.setModel(modeloTabla);

    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelDatosEmpleado = new javax.swing.JPanel();
        nombre = new javax.swing.JLabel();
        campoNombre = new javax.swing.JTextField();
        cargo = new javax.swing.JLabel();
        campoCargo = new javax.swing.JTextField();
        id = new javax.swing.JLabel();
        campoId = new javax.swing.JTextField();
        cargos = new javax.swing.JTabbedPane();
        administrador = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        tabsCRUD = new javax.swing.JTabbedPane();
        tabConsultar = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tablaBuscar = new javax.swing.JTable();
        botonCrear = new javax.swing.JButton();
        botonModificar = new javax.swing.JButton();
        botonEliminar = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        radioEmpleado = new javax.swing.JRadioButton();
        radioProducto = new javax.swing.JRadioButton();
        radioVenta = new javax.swing.JRadioButton();
        jPanel6 = new javax.swing.JPanel();
        botonBuscar = new javax.swing.JButton();
        comboBoxCampos = new javax.swing.JComboBox();
        campoBuscar = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        botonAgregar = new javax.swing.JButton();
        botonQuitar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaMenu = new javax.swing.JTable();
        cajero = new javax.swing.JPanel();
        tablaFactura = new javax.swing.JScrollPane();
        tablaPedido = new javax.swing.JTable();
        panelAccionesPedido = new javax.swing.JPanel();
        total = new javax.swing.JLabel();
        campoTotal = new javax.swing.JTextField();
        botonCerrarPedido = new javax.swing.JButton();
        botonImprimiFactura = new javax.swing.JButton();
        mesas = new javax.swing.JScrollPane();
        panelMesas = new javax.swing.JPanel();
        botonCerrarSesion = new javax.swing.JButton();
        botonCerrarAplicacion = new javax.swing.JButton();
        botonCambiarContraseña = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Interfaz Administrador"); // NOI18N
        setResizable(false);
        setUndecorated(true);

        panelDatosEmpleado.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Empleado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 2, 12), new java.awt.Color(102, 102, 102)));

        nombre.setText("Nombre : "); // NOI18N

        campoNombre.setEditable(false);
        campoNombre.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        cargo.setText("Cargo : "); // NOI18N

        campoCargo.setEditable(false);
        campoCargo.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        id.setText("ID : "); // NOI18N

        campoId.setEditable(false);
        campoId.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        javax.swing.GroupLayout panelDatosEmpleadoLayout = new javax.swing.GroupLayout(panelDatosEmpleado);
        panelDatosEmpleado.setLayout(panelDatosEmpleadoLayout);
        panelDatosEmpleadoLayout.setHorizontalGroup(
            panelDatosEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosEmpleadoLayout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(nombre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 388, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(133, 133, 133)
                .addComponent(cargo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoCargo, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(139, 139, 139)
                .addComponent(id, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoId, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                .addGap(140, 140, 140))
        );
        panelDatosEmpleadoLayout.setVerticalGroup(
            panelDatosEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosEmpleadoLayout.createSequentialGroup()
                .addGroup(panelDatosEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(id, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(campoId)
                    .addComponent(nombre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cargo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(campoCargo)
                    .addComponent(campoNombre))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cargos.setFont(new java.awt.Font("Tahoma", 0, 18));

        jLabel5.setFont(new java.awt.Font("Tahoma", 2, 14));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Menú del Día"); // NOI18N

        tabsCRUD.setFont(new java.awt.Font("Tahoma", 2, 14));

        tablaBuscar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaBuscarMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(tablaBuscar);

        botonCrear.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonCrear.setText("Crear");
        botonCrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCrearActionPerformed(evt);
            }
        });

        botonModificar.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonModificar.setText("Modificar");
        botonModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonModificarActionPerformed(evt);
            }
        });

        botonEliminar.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonEliminar.setText("Eliminar");
        botonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarActionPerformed(evt);
            }
        });

        radioEmpleado.setText("Empleado"); // NOI18N
        radioEmpleado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioEmpleadoActionPerformed(evt);
            }
        });

        radioProducto.setText("Producto"); // NOI18N
        radioProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioProductoActionPerformed(evt);
            }
        });

        radioVenta.setText("Venta"); // NOI18N
        radioVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioVentaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radioVenta)
                    .addComponent(radioEmpleado)
                    .addComponent(radioProducto))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(radioProducto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioEmpleado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioVenta)
                .addContainerGap())
        );

        botonBuscar.setText("Buscar"); // NOI18N
        botonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonBuscarActionPerformed(evt);
            }
        });

        comboBoxCampos.setAutoscrolls(true);
        comboBoxCampos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBoxCamposActionPerformed(evt);
            }
        });

        campoBuscar.setSelectionEnd(30);
        campoBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoBuscarActionPerformed(evt);
            }
        });
        campoBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                campoBuscarKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(comboBoxCampos, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(campoBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comboBoxCampos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonBuscar)
                    .addComponent(campoBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout tabConsultarLayout = new javax.swing.GroupLayout(tabConsultar);
        tabConsultar.setLayout(tabConsultarLayout);
        tabConsultarLayout.setHorizontalGroup(
            tabConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabConsultarLayout.createSequentialGroup()
                .addGroup(tabConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tabConsultarLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(botonCrear, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botonModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tabConsultarLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(tabConsultarLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        tabConsultarLayout.setVerticalGroup(
            tabConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabConsultarLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(tabConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCrear, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                    .addComponent(botonModificar, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                    .addComponent(botonEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE))
                .addContainerGap())
        );

        tabsCRUD.addTab("Actualización", tabConsultar);

        botonAgregar.setFont(new java.awt.Font("Tahoma", 1, 14));
        botonAgregar.setText("<---  Agregar");
        botonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarActionPerformed(evt);
            }
        });

        botonQuitar.setFont(new java.awt.Font("Tahoma", 1, 14));
        botonQuitar.setText("Quitar --->");
        botonQuitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonQuitarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonQuitar, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                    .addComponent(botonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
                .addComponent(botonQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tablaMenu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tablaMenu);

        javax.swing.GroupLayout administradorLayout = new javax.swing.GroupLayout(administrador);
        administrador.setLayout(administradorLayout);
        administradorLayout.setHorizontalGroup(
            administradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(administradorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(administradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(administradorLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(33, 33, 33)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(administradorLayout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(570, 570, 570)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabsCRUD, javax.swing.GroupLayout.PREFERRED_SIZE, 556, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(561, 561, 561))
        );
        administradorLayout.setVerticalGroup(
            administradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(administradorLayout.createSequentialGroup()
                .addGroup(administradorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(administradorLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(tabsCRUD, 0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, administradorLayout.createSequentialGroup()
                        .addGap(151, 151, 151)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, administradorLayout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)))
                .addGap(36, 36, 36))
        );

        tabsCRUD.getAccessibleContext().setAccessibleName("");

        cargos.addTab("ADMINISTRADOR", administrador);

        cajero.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cajeroMouseClicked(evt);
            }
        });

        tablaPedido.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Cantidad", "Producto", "Precio"
            }
        ));
        tablaFactura.setViewportView(tablaPedido);

        total.setFont(new java.awt.Font("Tahoma", 1, 18));
        total.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        total.setText("TOTAL");

        campoTotal.setEditable(false);

        botonCerrarPedido.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonCerrarPedido.setText("Cerrar Pedido");
        botonCerrarPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCerrarPedidoActionPerformed(evt);
            }
        });

        botonImprimiFactura.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonImprimiFactura.setText("Imprimir Factura");
        botonImprimiFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonImprimiFacturaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelAccionesPedidoLayout = new javax.swing.GroupLayout(panelAccionesPedido);
        panelAccionesPedido.setLayout(panelAccionesPedidoLayout);
        panelAccionesPedidoLayout.setHorizontalGroup(
            panelAccionesPedidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAccionesPedidoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botonCerrarPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonImprimiFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(54, 54, 54)
                .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
        );
        panelAccionesPedidoLayout.setVerticalGroup(
            panelAccionesPedidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAccionesPedidoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAccionesPedidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonImprimiFactura, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                    .addComponent(botonCerrarPedido, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAccionesPedidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(total, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
                        .addComponent(campoTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)))
                .addContainerGap())
        );

        mesas.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        mesas.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        mesas.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        javax.swing.GroupLayout panelMesasLayout = new javax.swing.GroupLayout(panelMesas);
        panelMesas.setLayout(panelMesasLayout);
        panelMesasLayout.setHorizontalGroup(
            panelMesasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1218, Short.MAX_VALUE)
        );
        panelMesasLayout.setVerticalGroup(
            panelMesasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1076, Short.MAX_VALUE)
        );

        mesas.setViewportView(panelMesas);

        javax.swing.GroupLayout cajeroLayout = new javax.swing.GroupLayout(cajero);
        cajero.setLayout(cajeroLayout);
        cajeroLayout.setHorizontalGroup(
            cajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cajeroLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(cajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelAccionesPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tablaFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 928, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(mesas, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43))
        );
        cajeroLayout.setVerticalGroup(
            cajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cajeroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(cajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(cajeroLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(tablaFactura, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(panelAccionesPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(mesas, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE))
                .addContainerGap())
        );

        cargos.addTab("CAJERO", cajero);

        botonCerrarSesion.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonCerrarSesion.setText("Cerrar Sesion"); // NOI18N
        botonCerrarSesion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCerrarSesionActionPerformed(evt);
            }
        });

        botonCerrarAplicacion.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonCerrarAplicacion.setText("Cerrar Aplicación"); // NOI18N
        botonCerrarAplicacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCerrarAplicacionActionPerformed(evt);
            }
        });

        botonCambiarContraseña.setFont(new java.awt.Font("Tahoma", 0, 18));
        botonCambiarContraseña.setText("Cambiar Contraseña"); // NOI18N
        botonCambiarContraseña.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCambiarContraseñaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelDatosEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(botonCambiarContraseña, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(botonCerrarAplicacion, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(botonCerrarSesion, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(cargos, javax.swing.GroupLayout.PREFERRED_SIZE, 1237, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(23, 23, 23))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCerrarSesion, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .addComponent(botonCerrarAplicacion, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .addComponent(botonCambiarContraseña, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
                .addGap(1, 1, 1)
                .addComponent(cargos, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDatosEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1303)/2, (screenSize.height-781)/2, 1303, 781);
    }// </editor-fold>//GEN-END:initComponents
    private void botonCerrarSesionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCerrarSesionActionPerformed
        parent.setVisible(true);
        this.dispose();
        Log.setEvento("Servidor", "INFO", "Se Cierra Interfaz de Administrador");
        Log.setEvento("Servidor", "INFO", "Se Ejecuta Interfaz de Iniciar Sesion.");
}//GEN-LAST:event_botonCerrarSesionActionPerformed

    private void botonCerrarAplicacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCerrarAplicacionActionPerformed
        // TODO add your handling code here:
        Log.setEvento("Servidor", "INFO", "Se Cierra la Apliacion");
        System.exit(1);        
}//GEN-LAST:event_botonCerrarAplicacionActionPerformed

    private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarActionPerformed
        // TODO add your handling code here:
        if (radioProducto.isSelected()) {
            for (int i = 0; i < tablaBuscar.getRowCount(); i++) {
                if (tablaBuscar.isRowSelected(i)) {
                    String id = String.valueOf(tablaBuscar.getValueAt(i, 0));
                    MenuDelDia.agregarAMenu(id);
                }

            }
        }
        radioProducto.doClick();
        generarMenuDelDia();
    }//GEN-LAST:event_botonAgregarActionPerformed

    private void botonQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonQuitarActionPerformed
        // TODO add your handling code here:
        for (int i = 0; i < tablaMenu.getRowCount(); i++) {
            if (tablaMenu.isRowSelected(i)) {
                String id = String.valueOf(tablaMenu.getValueAt(i, 0));
                MenuDelDia.quitarDeMenu(id);
            }

        }
        radioProducto.doClick();
        generarMenuDelDia();                
    }//GEN-LAST:event_botonQuitarActionPerformed

    private void botonCambiarContraseñaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCambiarContraseñaActionPerformed
        if (cambiarContraseña == null) {
            cambiarContraseña = new DialogoCambiarContraseña(this, true);
        }
        cambiarContraseña.resetAll();
        cambiarContraseña.setEmpleado(this.empleado);
        cambiarContraseña.pack();
        cambiarContraseña.setVisible(true);
}//GEN-LAST:event_botonCambiarContraseñaActionPerformed

    private void comboBoxCamposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBoxCamposActionPerformed
    // TODO add your handling code here:        
        
    }//GEN-LAST:event_comboBoxCamposActionPerformed

    private void botonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonBuscarActionPerformed
        // TODO add your handling code here:

        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();
        String campo = String.valueOf(comboBoxCampos.getSelectedItem());
        String busqueda = campoBuscar.getText();

        if (radioEmpleado.isSelected()) {
            if (busqueda.isEmpty()) {
                radioEmpleado.doClick();
            } else {

                List<Empleado> empleados = new ArrayList<Empleado>();
                empleados = BuscarPorCampo.buscarEmpleado(busqueda, campo);
                modeloTabla = generarCamposTabla();

                if (empleados == null) {
                    tablaBuscar.setModel(modeloTabla);
                } else {
                    modeloTabla.setRowCount(empleados.size());

                    for (int fila = 0; fila < empleados.size(); fila++) {
                        modeloTabla.setValueAt(empleados.get(fila).getId(), fila, 0);
                        modeloTabla.setValueAt(empleados.get(fila).getNombre(), fila, 1);
                        modeloTabla.setValueAt(empleados.get(fila).getCargo(), fila, 2);
                        modeloTabla.setValueAt(empleados.get(fila).getTelefono(), fila, 3);
                        modeloTabla.setValueAt(empleados.get(fila).getCelular(), fila, 4);
                    }
                    tablaBuscar.setModel(modeloTabla);
                }
            }

        }
        if (radioProducto.isSelected()) {
            if (busqueda.isEmpty()) {
                radioProducto.doClick();
            } else {

                List<Producto> productos = new ArrayList<Producto>();
                productos = BuscarPorCampo.buscarProducto(busqueda, campo);
                modeloTabla = generarCamposTabla();
                String eliminado = "", estaEnMenu = "";

                if (productos == null) {
                    tablaBuscar.setModel(modeloTabla);
                } else {
                    modeloTabla.setRowCount(productos.size());

                    for (int fila = 0; fila < productos.size(); fila++) {
                        if (productos.get(fila).getEliminado()) {
                            eliminado = "Si";
                        } else {
                            eliminado = "No";
                        }

                        if (productos.get(fila).getEstaEnMenu()) {
                            estaEnMenu = "Si";
                        } else {
                            estaEnMenu = "No";
                        }

                        modeloTabla.setValueAt(productos.get(fila).getId(), fila, 0);
                        modeloTabla.setValueAt(productos.get(fila).getNombre(), fila, 1);
                        modeloTabla.setValueAt(productos.get(fila).getTipo(), fila, 2);
                        modeloTabla.setValueAt(productos.get(fila).getPrecio(), fila, 3);
                        modeloTabla.setValueAt(estaEnMenu, fila, 4);
                        modeloTabla.setValueAt(eliminado, fila, 5);
                    }
                    tablaBuscar.setModel(modeloTabla);
                }
            }

        }
        if (radioVenta.isSelected()) {
            if (busqueda.isEmpty()) {
                radioVenta.doClick();
            } else {

                List<Pedido> pedidos = new ArrayList<Pedido>();
                pedidos = BuscarPorCampo.buscarPedido(busqueda, campo);
                modeloTabla = generarCamposTabla();
                String enCurso = "";

                if (pedidos == null) {
                    tablaBuscar.setModel(modeloTabla);
                } else {
                    modeloTabla.setRowCount(pedidos.size());
                    for (int fila = 0; fila < pedidos.size(); fila++) {
                        if (pedidos.get(fila).getEnCurso()) {
                            enCurso = "Si";
                        } else {
                            enCurso = "No";
                        }

                        modeloTabla.setValueAt(pedidos.get(fila).getId(), fila, 0);
                        modeloTabla.setValueAt(pedidos.get(fila).getMesa(), fila, 1);
                        modeloTabla.setValueAt(enCurso, fila, 2);
                        modeloTabla.setValueAt(pedidos.get(fila).getFecha(), fila, 3);
                        modeloTabla.setValueAt(pedidos.get(fila).getEmpleado().getNombre(), fila, 4);
                    }
                    tablaBuscar.setModel(modeloTabla);
                }
            }
        }
    }//GEN-LAST:event_botonBuscarActionPerformed

    private void radioVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioVentaActionPerformed
        // TODO add your handling code here:
        botonCrear.setEnabled(false);
        botonModificar.setEnabled(false);
        botonEliminar.setEnabled(false);
        comboBoxCampos.setEnabled(true);
        campoBuscar.setEnabled(true);
        radioEmpleado.setSelected(false);
        radioProducto.setSelected(false);
        campoBuscar.setText("");
        if (!radioEmpleado.isSelected() && !radioProducto.isSelected()) {
            radioVenta.setSelected(true);
        }

        comboBoxCampos.removeAllItems();
        comboBoxCampos.addItem("id");
        comboBoxCampos.addItem("mesa");
        comboBoxCampos.addItem("enCurso");
        comboBoxCampos.addItem("fecha");
        comboBoxCampos.addItem("empleado");

        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();

        List<Pedido> pedidos = new ArrayList<Pedido>();
        pedidos = DaoPedido.readAll();
        modeloTabla = generarCamposTabla();
        modeloTabla.setRowCount(pedidos.size());
        String enCurso = "";

        for (int fila = 0; fila < pedidos.size(); fila++) {
            if (pedidos.get(fila).getEnCurso() == true) {
                enCurso = "Si";
            } else {
                enCurso = "No";
            }

            modeloTabla.setValueAt(pedidos.get(fila).getId(), fila, 0);
            modeloTabla.setValueAt(pedidos.get(fila).getMesa(), fila, 1);
            modeloTabla.setValueAt(enCurso, fila, 2);
            modeloTabla.setValueAt(pedidos.get(fila).getFecha(), fila, 3);
            modeloTabla.setValueAt(pedidos.get(fila).getEmpleado().getNombre(), fila, 4);
        }
        tablaBuscar.setModel(modeloTabla);
    }//GEN-LAST:event_radioVentaActionPerformed

    private void radioProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioProductoActionPerformed
        // TODO add your handling code here:
        botonCrear.setEnabled(true);
        botonModificar.setEnabled(false);
        botonEliminar.setEnabled(false);
        comboBoxCampos.setEnabled(true);
        campoBuscar.setEnabled(true);
        radioEmpleado.setSelected(false);
        radioVenta.setSelected(false);
        campoBuscar.setText("");
        if (!radioEmpleado.isSelected() && !radioVenta.isSelected()) {
            radioProducto.setSelected(true);
        }

        comboBoxCampos.removeAllItems();
        comboBoxCampos.addItem("id");
        comboBoxCampos.addItem("nombre");
        comboBoxCampos.addItem("tipo");
        comboBoxCampos.addItem("precio");
        comboBoxCampos.addItem("estaEnMenu");
        comboBoxCampos.addItem("eliminado");

        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();

        List<Producto> productos = new ArrayList<Producto>();
        productos = DaoProducto.readAll();
        modeloTabla = generarCamposTabla();
        modeloTabla.setRowCount(productos.size());
        String estaEnMenu = "";
        String eliminado = "";

        for (int fila = 0; fila < productos.size(); fila++) {
            if (productos.get(fila).getEliminado() == true) {
                eliminado = "Si";
            } else {
                eliminado = "No";
            }

            if (productos.get(fila).getEstaEnMenu() == true) {
                estaEnMenu = "Si";
            } else {
                estaEnMenu = "No";
            }

            modeloTabla.setValueAt(productos.get(fila).getId(), fila, 0);
            modeloTabla.setValueAt(productos.get(fila).getNombre(), fila, 1);
            modeloTabla.setValueAt(productos.get(fila).getTipo(), fila, 2);
            modeloTabla.setValueAt(productos.get(fila).getPrecio(), fila, 3);
            modeloTabla.setValueAt(estaEnMenu, fila, 4);
            modeloTabla.setValueAt(eliminado, fila, 5);
        }
        tablaBuscar.setModel(modeloTabla);
    }//GEN-LAST:event_radioProductoActionPerformed

    private void radioEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioEmpleadoActionPerformed
        // TODO add your handling code here:
        botonCrear.setEnabled(true);
        botonModificar.setEnabled(false);
        botonEliminar.setEnabled(false);
        comboBoxCampos.setEnabled(true);
        campoBuscar.setEnabled(true);
        radioProducto.setSelected(false);
        radioVenta.setSelected(false);
        campoBuscar.setText("");
        if (!radioProducto.isSelected() && !radioVenta.isSelected()) {
            radioEmpleado.setSelected(true);
        }

        comboBoxCampos.removeAllItems();
        comboBoxCampos.addItem("id");
        comboBoxCampos.addItem("nombre");
        comboBoxCampos.addItem("cargo");
        comboBoxCampos.addItem("telefono");
        comboBoxCampos.addItem("celular");


        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();

        List<Empleado> empleados = new ArrayList<Empleado>();
        empleados = DaoEmpleado.readAll();
        modeloTabla = generarCamposTabla();
        modeloTabla.setRowCount(empleados.size());


        for (int fila = 0; fila < empleados.size(); fila++) {
            modeloTabla.setValueAt(empleados.get(fila).getId(), fila, 0);
            modeloTabla.setValueAt(empleados.get(fila).getNombre(), fila, 1);
            modeloTabla.setValueAt(empleados.get(fila).getCargo(), fila, 2);
            modeloTabla.setValueAt(empleados.get(fila).getTelefono(), fila, 3);
            modeloTabla.setValueAt(empleados.get(fila).getCelular(), fila, 4);
        }
        tablaBuscar.setModel(modeloTabla);
    }//GEN-LAST:event_radioEmpleadoActionPerformed

    private void botonCrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCrearActionPerformed
        if (radioProducto.isSelected()) {
            DialogoCrearProducto dp = new DialogoCrearProducto(this, true);
            dp.setVisible(true);
            radioProducto.doClick();
            generarMenuDelDia();
        }
        if (radioEmpleado.isSelected()) {
            DialogoCrearEmpleado de = new DialogoCrearEmpleado(this, true);
            de.setVisible(true);
            radioEmpleado.doClick();
        }
}//GEN-LAST:event_botonCrearActionPerformed

    private void cajeroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cajeroMouseClicked
    // TODO add your handling code here:
}//GEN-LAST:event_cajeroMouseClicked

    private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarActionPerformed
        if (radioProducto.isSelected()) {
            for (int i = 0; i < tablaBuscar.getRowCount(); i++) {
                if (tablaBuscar.isRowSelected(i)) {
                    String id = String.valueOf(tablaBuscar.getValueAt(i, 0));                    
                    NewOkCancelDialog okc = new NewOkCancelDialog(this, true, id, 0);
                    okc.setVisible(true);
                    radioProducto.doClick();
                    generarMenuDelDia();
                }

            }
        }
        if (radioEmpleado.isSelected()) {
            for (int i = 0; i < tablaBuscar.getRowCount(); i++) {
                if (tablaBuscar.isRowSelected(i)) {
                    String id = String.valueOf(tablaBuscar.getValueAt(i, 0));                    
                    NewOkCancelDialog okc = new NewOkCancelDialog(this, true, id, 1);
                    okc.setVisible(true);
                    radioEmpleado.doClick();
                    generarMenuDelDia();
                }

            }
        } 
}//GEN-LAST:event_botonEliminarActionPerformed

    private void campoBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoBuscarActionPerformed
  
    }//GEN-LAST:event_campoBuscarActionPerformed

    private void campoBuscarKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoBuscarKeyTyped
        // TODO add your handling code here:
        if (comboBoxCampos.getSelectedItem().toString().equals("id")) {
            if (campoBuscar.getText().length() > 2) {
                evt.consume();
            }
        }
        if (comboBoxCampos.getSelectedItem().toString().equals("telefono")) {
            if (campoBuscar.getText().length() > 6) {
                evt.consume();
            }
        }
        if (comboBoxCampos.getSelectedItem().toString().equals("celular")) {
            if (campoBuscar.getText().length() > 9) {
                evt.consume();
            }
        }
        if (comboBoxCampos.getSelectedItem().toString().equals("enCurso") || comboBoxCampos.getSelectedItem().toString().equals("estaEnMenu") || comboBoxCampos.getSelectedItem().toString().equals("eliminado") || comboBoxCampos.getSelectedItem().toString().equals("mesa")) {
            if (campoBuscar.getText().length() > 1) {
                evt.consume();
            }
        }
        if (comboBoxCampos.getSelectedItem().toString().equals("precio")) {
            if (campoBuscar.getText().length() > 4) {
                evt.consume();
            }
        }
        if (comboBoxCampos.getSelectedItem().toString().equals("precio")) {
            if (campoBuscar.getText().length() > 5) {
                evt.consume();
            }
        }
        if (comboBoxCampos.getSelectedItem().toString().equals("fecha")) {
            if (campoBuscar.getText().length() > 9) {
                evt.consume();
            }
        }

        if (campoBuscar.getText().length() > 34) {
            evt.consume();
        }
        
        
    }//GEN-LAST:event_campoBuscarKeyTyped

    private void botonCerrarPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCerrarPedidoActionPerformed
        // TODO add your handling code here:
        Pedido p = DaoPedido.read(idPedidoActual);
        p.setEnCurso(false);
        DaoPedido.update(p);
        cargarMesas(panelMesas);
        javax.swing.table.DefaultTableModel modeloTabla = new javax.swing.table.DefaultTableModel();
        modeloTabla.addColumn("Cantidad");
        modeloTabla.addColumn("Producto");
        modeloTabla.addColumn("Precio");
        tablaPedido.setModel(modeloTabla);
        campoTotal.setText("");
    }//GEN-LAST:event_botonCerrarPedidoActionPerformed

    private void botonImprimiFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonImprimiFacturaActionPerformed
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(VistaAdministrador.this);
        pj.printDialog();
        try {
            pj.print();
        } catch (Exception PrintException) {
        }
    }//GEN-LAST:event_botonImprimiFacturaActionPerformed

    private void botonModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonModificarActionPerformed
        // TODO add your handling code here:
        if (radioProducto.isSelected()) {
            int fila = tablaBuscar.getSelectedRow();
            String idPro = String.valueOf(tablaBuscar.getValueAt(fila, 0));
            DialogoCrearProducto dp = new DialogoCrearProducto(this, true, Integer.parseInt(idPro));
            dp.setVisible(true);
            radioProducto.doClick();
            generarMenuDelDia();
        }
        if (radioEmpleado.isSelected()) {
            int fila = tablaBuscar.getSelectedRow();
            String idEmp = String.valueOf(tablaBuscar.getValueAt(fila, 0));
            DialogoCrearEmpleado de = new DialogoCrearEmpleado(this, true, Integer.parseInt(idEmp));
            de.setVisible(true);
            radioEmpleado.doClick();
        }
        
        
}//GEN-LAST:event_botonModificarActionPerformed

    private void tablaBuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaBuscarMouseClicked
        // TODO add your handling code here:
        if ((!radioVenta.isSelected() && !radioEmpleado.isSelected() && !radioProducto.isSelected()) || radioVenta.isSelected()) {
            ;
        } else {
            botonModificar.setEnabled(true);
            botonEliminar.setEnabled(true);
        }
        
        
    }//GEN-LAST:event_tablaBuscarMouseClicked

    public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {

        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.black);
        Font fuente = new Font("Tahoma", Font.PLAIN, 12);
        int fontHeight = g2.getFontMetrics().getHeight();
        int fontDesent = g2.getFontMetrics().getDescent();
        double pageHeight = pageFormat.getImageableHeight() - fontHeight;
        double pageWidth = pageFormat.getImageableWidth();
        double tableWidth = (double) tablaPedido.getColumnModel().getTotalColumnWidth();
        double scale = 1;

        Date fechaActual = new Date();
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
        String cadenaFecha = formato.format(fechaActual);

        String total = campoTotal.getText();

        String empresa = "TU LUNCH. Para comer bien su casa, luego la nuestra";
        String datos = "Carrera 15 No 77 - 05 • Local 1-07 • Telefono.: 6221554";


        if (tableWidth >= pageWidth) {
            scale = (pageWidth / tableWidth) - 0.1;
        }

        double headerHeightOnPage = tablaPedido.getTableHeader().getHeight() * scale;
        double tableWidthOnPage = (tableWidth * scale);

        double oneRowHeight = (tablaPedido.getRowHeight() + tablaPedido.getRowMargin()) * scale;
        int numRowsOnAPage = (int) ((pageHeight - headerHeightOnPage) / oneRowHeight);
        double pageHeightForTable = oneRowHeight * numRowsOnAPage;
        int totalNumPages = (int) Math.ceil(((double) tablaPedido.getRowCount()) / numRowsOnAPage);
        if (pageIndex >= totalNumPages) {
            return NO_SUCH_PAGE;
        }

        g2.setFont(fuente);
        g2.drawString(empresa, (int) pageWidth / 2 - 45, 35);
        g2.drawString(datos, (int) pageWidth / 2 - 53, 55);
        g2.drawString("Fecha: " + cadenaFecha, 40, 90);
        g2.drawString("Total:               " + total, 400, 110);
        g2.translate(40, 130);

        g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        g2.translate(0f, headerHeightOnPage);
        g2.translate(0f, (-pageIndex * pageHeightForTable));


        if (pageIndex + 1 == totalNumPages) {
            int lastRowPrinted = numRowsOnAPage * pageIndex;
            int numRowsLeft = tablaPedido.getRowCount() - lastRowPrinted;
            g2.setClip(0, (int) (pageHeightForTable * pageIndex), (int) Math.ceil(tableWidthOnPage), (int) Math.ceil((oneRowHeight * numRowsLeft)));

        } else {
            g2.setClip(0, (int) (pageHeightForTable * pageIndex), (int) Math.ceil(tableWidthOnPage), (int) Math.ceil(pageHeightForTable));
        }

        g2.scale(scale, scale);
        tablaPedido.paint(g2);
        g2.scale(1 / scale, 1 / scale);
        g2.translate(0f, (pageIndex * pageHeightForTable));
        g2.translate(0f, -headerHeightOnPage);
        g2.setClip(0, 0, (int) Math.ceil(tableWidthOnPage), (int) Math.ceil(headerHeightOnPage));
        g2.scale(scale, scale);
        tablaPedido.getTableHeader().paint(g2);



        return Printable.PAGE_EXISTS;
    }

    /**
     * @param args the command line arguments
     */
    public static void ejecutar(final JFrame parent, final Empleado empleado) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VistaAdministrador(parent, empleado);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel administrador;
    private javax.swing.JButton botonAgregar;
    private javax.swing.JButton botonBuscar;
    private javax.swing.JButton botonCambiarContraseña;
    private javax.swing.JButton botonCerrarAplicacion;
    private javax.swing.JButton botonCerrarPedido;
    private javax.swing.JButton botonCerrarSesion;
    private javax.swing.JButton botonCrear;
    private javax.swing.JButton botonEliminar;
    private javax.swing.JButton botonImprimiFactura;
    private javax.swing.JButton botonModificar;
    private javax.swing.JButton botonQuitar;
    private javax.swing.JPanel cajero;
    private javax.swing.JTextField campoBuscar;
    private javax.swing.JTextField campoCargo;
    private javax.swing.JTextField campoId;
    private javax.swing.JTextField campoNombre;
    private javax.swing.JTextField campoTotal;
    private javax.swing.JLabel cargo;
    private javax.swing.JTabbedPane cargos;
    private javax.swing.JComboBox comboBoxCampos;
    private javax.swing.JLabel id;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane mesas;
    private javax.swing.JLabel nombre;
    private javax.swing.JPanel panelAccionesPedido;
    private javax.swing.JPanel panelDatosEmpleado;
    private javax.swing.JPanel panelMesas;
    private javax.swing.JRadioButton radioEmpleado;
    private javax.swing.JRadioButton radioProducto;
    private javax.swing.JRadioButton radioVenta;
    private javax.swing.JPanel tabConsultar;
    private javax.swing.JTable tablaBuscar;
    private javax.swing.JScrollPane tablaFactura;
    private javax.swing.JTable tablaMenu;
    private javax.swing.JTable tablaPedido;
    private javax.swing.JTabbedPane tabsCRUD;
    private javax.swing.JLabel total;
    // End of variables declaration//GEN-END:variables
}
